<?php
// Tim'Roster
// Copyright (c) 2011 Nicolas Nallet <aspgic2@gmail.com>
//
// This file is part of Tim'Roster.
//
// Tim'Roster is free software; you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation; either version 3 of the License, or
// (at your option) any later version.
//
// Tim'Roster is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program; if not, write to the Free Software Foundation,
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA

/** Generating table and table elements functions **/


/**
 * (PHP 5)<br/>
 * Generate a HTML two cells table
 * @param string $content1
 * @param string $content2
 * @return string
 */
function generate_2cells_horizontal_table($content1, $content2){
    return '<table ><tr>'
          .'    <td valign=\'top\'>'.$content1.'</td>'
          .'    <td valign=\'top\'>'.$content2.'</td>'
          .'</tr></table>';
}


/**
 * (PHP 5)<br/>
 * Generate a HTML table header
 * @param array $column_array array of column names
 * @param int $width width of the table (if null width = 480)
 * @param bool $has_footer 
 * @return string
 */
function generate_html_table_header($column_array, $width, $has_footer){
    $table = '';

    if (!isset($width)) {
        $width = 480;
    }

    if ((is_array($column_array)) && (count($column_array) > 0)){
        $table = '<table id="rounded-corner" width='.$width.'>
        <thead>
            <tr>
                <th scope="col" class="rounded-left">'.$column_array[0].'</th>';

            for ($i = 1; $i < (count($column_array) - 1); $i++) {
                $table .= '<th scope="col" >'.$column_array[$i].'</th>';
            }

        $table .= count($column_array) >= 2 ?  '<th scope="col" class="rounded-right">'.$column_array[count($column_array) - 1].'</th>'
                                                    :  '<th scope="col" class="rounded-right"></th>';

        
         $table .= '</tr></thead>';

         if ((isset($has_footer)) && ($has_footer)){
             $table .= '<tfoot>
                        <tr>
                            <td colspan="'.(count($column_array) - 1).'" class="rounded-foot-left"></td>
                            <td class="rounded-foot-right">&nbsp;</td>
                        </tr>
                    </tfoot>';
         }
    

        $table .= '<tbody>';
    }

    return $table;
}



function generate_html_sortable_table_header($column_array, $upper_header){
    $table = '';

    if ((is_array($column_array)) && (count($column_array) > 0)){
        $table = '<table class="tablesorter" >
        <thead>';

        if (isset($upper_header)){
            $table .= '<tr>';

            for ($i = 0; $i < (count($upper_header)); $i++) {
                $table .= '<th colspan="'.$upper_header[$i][1].'">'.$upper_header[$i][0].'</th>';
            }

            $table .= '</tr>';
        }

        $table .= '<tr>';

        for ($i = 0; $i < (count($column_array)); $i++) {
            $table .= '<th>'.$column_array[$i].'</th>';
        }

        $table .= '</tr></thead>';

        

        $table .= '<tbody>';
    }

    return $table;
}



/**
 * (PHP 5)<br/>
 * Generate a 2 columns html table row 
 * @param string $first_col_val first column value
 * @param string $second_col_val second column value
 * @return string
 */
function generate_html_table_row($first_col_val, $second_col_val){
    return '<tr><td >'.$first_col_val.'</td><td>'.$second_col_val.'</td></tr>';
}

/**
 * (PHP 5)<br/>
 * Generate a 2 columns html table row with valign = center
 * @param string $first_col_val first column value
 * @param string $second_col_val second column value
 * @return string
 */
function generate_html_table_center_row($first_col_val, $second_col_val){
    return '<tr><td valign="center">'.$first_col_val.'</td><td valign="center">'.$second_col_val.'</td></tr>';
}

/**
 * (PHP 5)<br/>
 * Generate html table footer
 * @return string
 */
function generate_html_table_footer(){
    return '</tbody>
            </table>';
}

?>